package cn.flying.cloud.system.resource.service.impl;

import java.io.Serializable;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import cn.flying.cloud.base.common.vo.PageRequest;
import cn.flying.cloud.base.common.vo.PageResponse;
import cn.flying.cloud.system.resource.entity.SysResUrl;
import cn.flying.cloud.system.resource.mapper.SysResUrlMapper;
import cn.flying.cloud.system.resource.service.SysResUrlService;

/**
 * 资源url表 服务实现类
 *
 * @author system
 * @since 2024-06-13 20:08:02
 */
@Service
public class SysResUrlServiceImpl extends ServiceImpl<SysResUrlMapper, SysResUrl> implements SysResUrlService {
    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    /**
     * 分页查询资源url表数据
     *
     * @param request
     * @return
     */
    @Override
    public PageResponse getPageList(PageRequest<SysResUrl> request) {
        SysResUrl param = request.getParam();
        LambdaQueryWrapper<SysResUrl> wrapper = getLambdaQueryWrapper(param);
        // wrapper TODO
        Page<SysResUrl> page = this.page(new Page<>(request.getPageNum(), request.getPageSize()), wrapper);
        return new PageResponse(page.getTotal(), (int) page.getCurrent(), page.getRecords());
    }

    /**
     * 构建查询对象
     *
     * @param param
     * @return
     */
    private LambdaQueryWrapper<SysResUrl> getLambdaQueryWrapper(SysResUrl param) {
        LambdaQueryWrapper<SysResUrl> wrapper = new LambdaQueryWrapper<>();
        // wrapper TODO
        return wrapper;
    }

    /**
     * 列表查询资源url表数据
     *
     * @param sysResUrl
     * @return
     */
    @Override
    public List<SysResUrl> getList(SysResUrl sysResUrl) {
        LambdaQueryWrapper<SysResUrl> wrapper = new LambdaQueryWrapper<>();
        // wrapper TODO
        List<SysResUrl> list = this.list(wrapper);
        return list;
    }

    /**
     * 查询资源url表详情数据
     *
     * @param sysResUrl
     * @return
     */
    @Override
    public SysResUrl getOneObj(SysResUrl sysResUrl) {
        LambdaQueryWrapper<SysResUrl> wrapper = new LambdaQueryWrapper<>();
        // wrapper TODO
        return this.getOne(wrapper);
    }


    /**
     * 新增资源url表数据
     *
     * @param sysResUrl
     * @return
     */
    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean createObj(SysResUrl sysResUrl) {
        return this.save(sysResUrl);
    }

    /**
     * 更新资源url表数据
     *
     * @param sysResUrl
     * @return
     */
    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean updateObj(SysResUrl sysResUrl) {
        return this.saveOrUpdate(sysResUrl);
    }

    /**
     * 删除资源url表数据
     *
     * @param sysResUrl
     * @return
     */
    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean deleteObj(SysResUrl sysResUrl) {
        LambdaQueryWrapper<SysResUrl> wrapper = new LambdaQueryWrapper<>();
        // wrapper TODO
        return this.remove(wrapper);
    }

    /**
     * 根据Id删除
     *
     * @param id
     * @return
     */
    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean deleteById(Serializable id) {
        return this.removeById(id);
    }
}
